Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change RTMPStream readyState observers to open #1375

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

levs42
Copy link
Contributor

@levs42 levs42 commented Feb 9, 2024

Description & motivation

This small change makes readyState open. It helps to observe changes of readyState property of IOStream.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Screenshots:

@@ -416,7 +416,7 @@ open class RTMPStream: IOStream {
return metadata
}

override public func readyStateWillChange(to readyState: IOStream.ReadyState) {
override open func readyStateWillChange(to readyState: IOStream.ReadyState) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the goal is to detect changes in the readyState, I think it would be more iOS-like to provide a dedicated delegate method. Would achieving the requirements be difficult with such an approach?

Copy link
Contributor Author

@levs42 levs42 Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please take a look
Upd: Fixed an error

@levs42 levs42 force-pushed the rtmpstream-declaration branch 2 times, most recently from 1d72afb to 88fbe4b Compare February 12, 2024 19:38
@@ -34,6 +34,10 @@ public protocol IOStreamDelegate: AnyObject {
func stream(_ stream: IOStream, audioErrorOccurred error: IOAudioUnitError)
/// Tells the receiver to the stream opened.
func streamDidOpen(_ stream: IOStream)
/// Tells the receiver that the ready state will change.
func stream(_ stream: IOStream, willChange readyState: IOStream.ReadyState)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Cocoa frameworks, abbreviations like "didChange" or "willChange" are not common, so could you please change them to "didReadyStateChange" or "willReadyStateChange"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated it to "willChangeReadyState" and "didChangeReadyState" as it sounds more readable. Please take a look.

@@ -458,6 +462,7 @@ open class IOStream: NSObject {
/// A handler that receives stream readyState will update.
/// - Warning: Please do not call this method yourself.
open func readyStateWillChange(to readyState: ReadyState) {
delegate?.stream(self, willChange: readyState)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it's located here, I tend to forget to implement it in the subclass. Therefore, I request the following changes.

public var readyState: ReadyState = .initialized {
    willSet {
        guard readyState != newValue else {
            return
        }
        delegate?.stream(self, willChange: newValue)
        readyStateWillChange(to: newValue)
    }
    didSet {
        guard readyState != oldValue else {
            return
        }
        readyStateDidChange(to: readyState)
        delegate?.stream(self, didChange: readyState)
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, please take a look

@levs42 levs42 force-pushed the rtmpstream-declaration branch from 88fbe4b to 1d72595 Compare February 13, 2024 18:39
Copy link
Owner

@shogo4405 shogo4405 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@shogo4405 shogo4405 merged commit c712fe7 into shogo4405:main Feb 14, 2024
1 check passed
@shogo4405 shogo4405 added this to the 1.7.4 milestone Feb 14, 2024
@levs42 levs42 deleted the rtmpstream-declaration branch May 7, 2024 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants